<template>
	<view calss="container">
		<tui-list-view class="tui-list-view">
			<tui-list-cell @click="edit_avatar" :arrow="true" class="tui-list">
				<view class="tui-list-cell-name">设置头像</view>
				<image :src="my_info.status==1&&my_info.image_url?my_info.image_url:image_url" class="image_cl"></image>
			</tui-list-cell>
			<tui-list-cell @click="edit_nick_name" :arrow="true" class="tui-list">
				<view class="tui-list-cell-name">昵称</view>
				<view class="tui-right">{{my_info.nick_name?my_info.nick_name:'未设置'}}</view>
			</tui-list-cell>
			<tui-list-cell @click="edit_phone" :arrow="true" class="tui-list">
				<view class="tui-list-cell-name">手机号</view>
				<view class="tui-right">{{my_info.phone?my_info.phone:'未设置'}}</view>
			</tui-list-cell>
		</tui-list-view>
		
		<tui-list-view class="tui-list-view">
			<view class="s-btn" @tap="logout">退出登录</view>
		</tui-list-view>
	</view>
</template>
<script>
	import tuiListView from "@/components/list-view/list-view"
	import tuiListCell from "@/components/list-cell/list-cell"
	import Setting from './setting-model.js'
	var setting = new Setting(); 
	export default {
		components: {
			tuiListView,
			tuiListCell
		},
		data() {
			return {
				my_info:[],
				image_url:'../../static/images/my/mine_def_touxiang_3x.png',//默认头像
			}
		},
		onShow(){
			this.my();
		},
		methods: {
			//我的信息
			my(){
				var that = this;
				setting.my((res)=>{
					if(res.code==8888){
						that.my_info = res.data;
					}
				})
			},
			//退出登录
			logout(){
				setting.show_modal({content:'确定要退出登录吗！'},(res)=>{
					if (res.confirm) {
						setting.logout((res)=>{
							if(res.code == 8888){
								setting.remove_storage('token');
								setting.remove_storage('token_type');
								setting.switch_tab('../my/my');return;
							}
						})
					}	
				})
			},
			//头像更换
			edit_avatar(){
				var that = this;
				setting.upload(1,(res)=>{
					if(res.code == 8888){
						that.my_info.image_url = res.data.image_url;
						setting.edit_avatar(res.data.image_id,that,(res)=>{
							if(res.code == 8888){
								setting.show_tips({title:res.msg});return;
							}
						});
					}
				})
			},
			//修改昵称
			edit_nick_name(){
				setting.navigate_to('../edit_nick_name/edit_nick_name');return;
			},
			//修改手机号
			edit_phone(){
				setting.navigate_to('../edit_phone/edit_phone');return;
			}
		}
	}
</script>
<style>
	@import url("setting.css");
</style>
